package installer;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

public class SkylineRemover {

	private static JdbcTemplate jdbcTemplate;
	private static String SITE_TABLE = "site";
	private static String User_TABLE = "user";

	public static void initalJdbcTemplate() {
		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"config/context/applicationContext.xml");
		jdbcTemplate = (JdbcTemplate) ctx.getBean("jdbcTemplate");
	}

	private static String genRemoveSql(String tableName) {
		return "drop table " + SITE_TABLE + ";";
	}

	private static void removing(String tableName) {
		try {
			System.out.println("SkylineRemover is removing Site...");
			jdbcTemplate.execute(genRemoveSql(SITE_TABLE));
			System.out.println("SkylineRemover removed Site successfully!");
		} catch (Exception e) {
			System.out.println("Some errors arise while removing Site!");
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		initalJdbcTemplate();

		removing(SITE_TABLE);
		removing(User_TABLE);
	}

}
